//
//  RdClueSearchView.m
//  RecodeOrder
//
//  Created by 李坤 on 2018/5/9.
//  Copyright © 2018年 程强. All rights reserved.
//

#import "RdClueSearchView.h"

@interface RdClueSearchView ()
@property (strong, nonatomic) UIView *contentView;
@property (strong, nonatomic) void(^searchBlock)(void);
@property (strong, nonatomic) void(^filterBlock)(void);
@end

@implementation RdClueSearchView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.contentView.backgroundColor = RGBColor(237, 237, 237);
        [self line];
    }
    return self;
}
- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc]init];
        _contentView.layer.cornerRadius = 3.0;
        [self addSubview:_contentView];
        [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(15);
            make.right.equalTo(self).offset(-15);
            make.height.equalTo(self).offset(-20);
        }];
    }
    return _contentView;
}
- (void)line
{
    UIView *line = [UIView new];
    line.backgroundColor = RGBColor(237, 237, 237);
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self);
        make.height.equalTo(@1);
        make.centerX.equalTo(self);
        make.bottom.equalTo(self);
    }];
    
    UIImageView *icon = [[UIImageView alloc]initWithImage:LoadImage(@"clue_search")];
    [self addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.width.equalTo(@18);
        make.height.equalTo(@18);
        make.centerX.equalTo(_contentView).offset(-20);
    }];
    
    UILabel *titleLbl = [[UILabel alloc]init];
    titleLbl.text = @"搜索";
    titleLbl.font = [UIFont systemFontOfSize:15.0];
    titleLbl.textColor = RGBColor(100, 100, 100);
    [self addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.width.equalTo(@40);
        make.height.equalTo(@30);
        make.left.equalTo(icon.mas_right).offset(5);
    }];
    
    UIButton *tapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:tapBtn];
    [tapBtn addTarget:self action:@selector(searchClick:) forControlEvents:UIControlEventTouchUpInside];
    [tapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_contentView);
    }];
    
//    UIButton *filterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [filterBtn setTitle:@"筛选" forState:UIControlStateNormal];
//    [filterBtn setTitleColor:RGBColor(100, 100, 100) forState:UIControlStateNormal];
//    filterBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
//    [self addSubview:filterBtn];
//    [filterBtn addTarget:self action:@selector(filterClick:) forControlEvents:UIControlEventTouchUpInside];
//    [filterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_contentView.mas_right).offset(5);
//        make.right.equalTo(self).offset(-5);
//        make.centerY.equalTo(self);
//        make.height.equalTo(_contentView);
//    }];
}
- (void)searchClick:(UIButton *)sender
{
    if (self.searchBlock) {
        self.searchBlock();
    }
}
- (void)searchClueHandler:(void(^)(void))block
{
    self.searchBlock = block;
}
- (void)filterClick:(UIButton *)sender
{
    if (self.filterBlock) {
        self.filterBlock();
    }
}
- (void)filterClueHandler:(void(^)(void))block
{
    self.filterBlock = block;
}
@end
